package cn.edu.sjtu.se.dslab.util;

import java.text.SimpleDateFormat;
import java.util.Date;

import cn.edu.sjtu.se.dslab.component.data.DomainEntity;
import cn.edu.sjtu.se.dslab.component.method.ComponentInterface;
import cn.edu.sjtu.se.dslab.component.method.MethodComponent;

public class Util {
	public static Date string2Date(String dateString) {
		Date date;
		SimpleDateFormat myFmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			date = myFmt.parse(dateString + " 01:00:00");
			return date;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return null;
		}
	}
	
	public static String upperFirstLetter(String string){
		String firstLetterString = ""+string.charAt(0);
		return firstLetterString.toUpperCase()+string.substring(1);
	}
	
	public static String lowerrFirstLetter(String string){
		String firstLetterString = ""+string.charAt(0);
		return firstLetterString.toLowerCase()+string.substring(1);
	}
	
	public static String getEntityName(DomainEntity entity){
		return upperFirstLetter(entity.getName().replace(" ", "_"));
	}
	
	public static String getEntityFileName(DomainEntity entity){
		return entity.getName().replace(" ", "_").toLowerCase()+".h";
	}
	
	public static String getEntityImplFileName(DomainEntity entity){
		return entity.getName().replace(" ", "_").toLowerCase()+".c";
	}
	
	public static String getInterfaceName(ComponentInterface cInterface){		
		return cInterface.getUri().split(":")[1]+"/"+cInterface.getName().replace(" ", "_").toLowerCase()+".h";
	}
	
	
	public static String getImplementName(MethodComponent component){
		return component.getName().replace(" ", "_").toLowerCase()+".c";
	}
}
